#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h> 


int main(int argc,char *argv[])
{
	int connectfd;
	struct sockaddr_in remoteaddr;
    	struct hostent *he;	
    	he = gethostbyname("127.0.0.1");
	memset(&remoteaddr,0x00,sizeof(remoteaddr));
	remoteaddr.sin_family = AF_INET;
	remoteaddr.sin_port = htons(6666);
	remoteaddr.sin_addr = *((struct in_addr *)he->h_addr);
    	connectfd = socket(AF_INET,SOCK_STREAM,0);
    	if (-1 == connectfd) 
	{
        	perror("socket");
        	exit(0);
    	}
    	if( -1 == connect(connectfd,(struct sockaddr*)&remoteaddr,sizeof(struct sockaddr_in)))
    	{
		perror("connect");
		exit(0);
    	}
	printf("连接成功\n");
	body(connectfd);//程序主体
	printf("输入quit退出:");
	while(1)
	{
		char buf[100];
		fgets(buf,100,stdin);
		send(connectfd,buf,sizeof(buf),0);
		if(strcmp(buf,"quit\n")==0)
		{
			break;
		}
	}
    	close(connectfd);	
    	return 0;
}

